// generated 2005/6/24 0:15:12 CST by xihels@163.com
//


#ifndef _MAINWINDOW_HH
#  define _MAINWINDOW_HH

#if !defined(GLADEMM_DATA)
#define GLADEMM_DATA 
#include <gtkmm/accelgroup.h>

class GlademmData
{  
        
        Glib::RefPtr<Gtk::AccelGroup> accgrp;
public:
        
        GlademmData(Glib::RefPtr<Gtk::AccelGroup> ag) : accgrp(ag)
        {  
        }
        
        Glib::RefPtr<Gtk::AccelGroup>  getAccelGroup()
        {  return accgrp;
        }
};
#endif //GLADEMM_DATA

#include <gtkmm/window.h>
#include <gtkmm/button.h>
#include <gtkmm/image.h>

#include "CycloneMenu.h"
#include "BuddyList.h"
#include "QQSession.h"
#include "Unit.h"
#include <vector>

using std::vector;
using std::binary_function;

#include <ext/hash_map>
using __gnu_cxx::hash_map;

class QQUser;
class LoginWindow;
class FindBuddyWindow;
class PasswdErrorDialog;
class DisconnectDialog;
class PreferWindow;

class MainWindow : public Gtk::Window
{  
    public:
	typedef vector<QQSession*> Sessions;
	MainWindow();
	~MainWindow();

	// 用来在启动时,弹出登录对话框(只调用一次);
	void on_initalize();

	void login(const QQUser& user);
	

    public:
	void refreshFriendsListStatus(const QQSession& session)
	{
	    buddyList->refreshFriendsListStatus(session);
	}
	void refreshFriendStatus(const QQSession& session,
	       	FriendInfo& friendinfo)
	{
	    buddyList->refreshFriendStatus(session, friendinfo);
	}
		
	void refreshFriendsList(const QQSession& session,
	       	int refreshtype = ADD_TREEITEM)
	{
	    buddyList->refreshFriendsList(session, refreshtype);
	}
	
	void refreshFriend(const QQSession& session, 
		FriendInfo& friendinfo)
	{
	    buddyList->refreshFriend(session, friendinfo);
	}
	
	void refreshClustersList(const QQSession& session, 
		int refreshtype = ADD_TREEITEM)
	{
	    buddyList->refreshClustersList(session, refreshtype);
	}
	
	void refreshCluster(const QQSession& session,
		ClusterInfo& clusterinfo)
	{
	    buddyList->refreshCluster(session, clusterinfo);
	}

	void refreshGroupsList(const QQSession& session, 
		int refreshtype = ADD_TREEITEM)
	{
	    buddyList->refreshGroupsList(session, refreshtype);
	}

	void refreshSelfStatus(const QQSession& session);
	void loginError(QQSession* session, const string& message);


    public:
	void on_buddyChat_activate();
	void on_buddyLog_activate();
	void on_buddyInfo_activate();
	void on_buddyRemove_activate();

	void on_groupNew_activate();
	void on_groupRemove_activate();

	void on_userOnline_activate();
	void on_userAway_activate();
	void on_userHidden_activate();
	void on_userInfo_activate();
	void on_userExit_activate();
	void on_userNew_activate();
	
	void on_findBuddy_activate();
	void on_about_activate();

	void on_setPrefer_activate();
//	bool on_buttonUser_press_event(GdkEventButton *ev);

	bool on_timeout();	// 超时函数
	    
	bool on_delete_event(GdkEventAny* ev);

	void on_buddyList_row_changed();

	// 登录对话框回调函数 
	void on_loginWindow_ok(LoginWindow* dlg);
	void on_loginWindow_cancel(LoginWindow* dlg);

	// 登录出错对话框回调函数
	void on_passwdErrorDialog_ok(PasswdErrorDialog* dlg); 
	
	// 连接断开对话框回调函数
	void on_disconnectDialog_yes(DisconnectDialog* dlg);
	void on_disconnectDialog_no(DisconnectDialog* dlg);

	// 查找好友对话框回调
	void on_findBuddyWindow_close(FindBuddyWindow* dlg);
	void on_preferWindow_close(PreferWindow* dlg);
	void on_SearchUser(QQSession &session);
	void toggle_visibility();
    private:
	void on_btnSystem_clicked();
	void on_btnUser_clicked();
	void on_popup_menu_pos(int& x, int& y, bool& push_in, int id);
	QQSession* getSelectSession();
    private:
	SystemMenu	systemMenu;
	UserMenu	userMenu;
	Sessions	sessionList;

	Glib::RefPtr<Gdk::Pixbuf> pixUser[3];

	GlademmData*	gmm_data;
	FindBuddyWindow* findBuddyWindow;
	PreferWindow *  preferWindow;
	BuddyList*	buddyList;
	Gtk::Button*	buttonSystem;
	Gtk::Button*	buttonUser;
	Gtk::Image*	imageUser;
	int win_x,win_y;
	//StatusIcon * statusIcon;
    private:
	MainWindow(const MainWindow& rhs);		// 禁止拷贝
	MainWindow& operator =(const MainWindow& rhs); // 禁止拷贝
};



#endif
